package com.boil.qz.safekavass.model;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

/**
 * Created by ChenYong on 2017-07-04.
 * <br>
 * 基础实体类。
 */
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
    /**
     * 序列化 ID
     */
    private static final long serialVersionUID = 3663888457117309443L;
    /**
     * 编号，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;

    /**
     * 默认构造器。
     */
    public BaseEntity() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BaseEntity id1 = (BaseEntity) o;

        return id != null ? id.equals(id1.id) : id1.id == null;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Id{");
        sb.append("id=").append(id);
        sb.append('}');
        return sb.toString();
    }
}